package com.dayatang.android.Activity;

import android.app.TabActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.TabHost;
import android.widget.TabHost.OnTabChangeListener;
import android.widget.TabHost.TabSpec;
import android.widget.TabWidget;
import android.widget.TextView;

public class ReportsActivity extends TabActivity{
	
	private TabHost _tabHost;
	
	private TabWidget tabWidget;
	
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		
		setContentView(R.layout.reports_activity);
		
		_tabHost = getTabHost();
		
		tabWidget = _tabHost.getTabWidget();
		
	    AddTabPage(new Intent(this, ConstructionProjectProductionValueActivity.class),getString(R.string.reports_tab_one));
	    AddTabPage(new Intent(this, ProjectOutputallByYearActivity.class),getString(R.string.reports_tab_two));
	    AddTabPage(new Intent(this, ProjectOutputallByMonthActivity.class),getString(R.string.reports_tab_eight));
	    AddTabPage(new Intent(this, ProjectOutputallByYearActivity.class),getString(R.string.reports_tab_three));
	    AddTabPage(new Intent(this, DivisionOutputallActivity.class),getString(R.string.reports_tab_four));
	    AddTabPage(new Intent(this, SpecialtyOutputallActivity.class),getString(R.string.reports_tab_five));
	    AddTabPage(new Intent(this, ProjectExpenditureActivity.class),getString(R.string.reports_tab_six));
	    AddTabPage(new Intent(this, DivisionExpenditureActivity.class),getString(R.string.reports_tab_seven));
	     
	     InitTabBackImage();
	     TabChange();
	}
	
	private void TabChange(){
		
		 _tabHost.setOnTabChangedListener(new OnTabChangeListener() {
				public void onTabChanged(String tabId) {
					InitTabBackImage();
				}
		});
		
	}
	
	
	private void InitTabBackImage(){
		
		for(int i = 0,len = tabWidget.getChildCount(); i < len ; i++){
			
			View vvv = tabWidget.getChildAt(i);

			if(_tabHost.getCurrentTab()==i){
	            vvv.setBackgroundDrawable(getResources().getDrawable(R.drawable.background_div_bg));
			}
			else {
	            vvv.setBackgroundDrawable(getResources().getDrawable(R.drawable.background_login_div_bg));
			}

	     }
	}
	
	
	private void AddTabPage(Intent intent,String tabSpecName) {
        
        TabSpec tabSpec = _tabHost.newTabSpec(tabSpecName);
        
        LayoutInflater inflater = LayoutInflater.from(this);    
		View view = inflater.inflate(R.layout.tabicon, null);   
        
		TextView textView = (TextView)view.findViewById(R.id.tabicon_text);
		textView.setText(tabSpecName);
		
        tabSpec.setIndicator(view);
        tabSpec.setContent(intent);          
        _tabHost.addTab(tabSpec);
    }
    
}
